var RSA = require('rsa.js')


//公钥
var publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCanPsssQ9kNErQbEvUIm6pXzISY1sre1SC2Ukan7P5nzsk/TsMMv3O54BuncR/yy19CeohiTaipWVHEY0AQdg5ntBLtkk8059XGop6FvdrHSjFtmtrzK4/Q2f0zr7dFYlG/2Nmx3BLYjjoaSRPX2cwYeOmLy7xiTnoZ5UXE/RhkwIDAQAB';
//私钥
var privateKey = 'MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJqc+yyxD2Q0StBsS9QibqlfMhJjWyt7VILZSRqfs/mfOyT9Owwy/c7ngG6dxH/LLX0J6iGJNqKlZUcRjQBB2Dme0Eu2STzTn1cainoW92sdKMW2a2vMrj9DZ/TOvt0ViUb/Y2bHcEtiOOhpJE9fZzBh46YvLvGJOehnlRcT9GGTAgMBAAECgYEAgo3pvfwovfk17zZy9Ua54MTkeAhzlIzIeNDXXObbxv2AqKQ3tv5buNlcZotLwIkk+P9lNzow6zf0BAW65Su0UuX6+9nNE7Cd3TxL0xymggPnF1eL7a6OcSaTlQ/CF6PudAg9S5hmuS6FmAhxVlVbbuGSsFGldpMx4dczUznFfwECQQDt5gQn82ptls5d2D7F6CepPL2fZSi+tIX+376VGKm+QwlNlgon2OIkA3DdeLbSnIqLfgNXYRJX5Dky+BHWRroTAkEApmCqQzyPu/bFVl48JaohdqVv7XL1cP/wFNuAJcn4yNRD1a9P1qT2cmaaJL1HErUBkSpyT0p901hyK1UwqkCqgQJASTpNOzLtJrCN80sV/3s3ghuFTuQnh5QvzsV2d5Rw43TlDzHJDHzxFx7MBhAbTncLGmb+hk4GBHHmvW6opul8awJAJ5KubLem6GpVnalkXQEOXI4VBUFmp634iL18yYA0sG/sgpLkRoWOKL/Gwh5THVv4N3MFJV7udqp+3Vex74zaAQJAJUwsz0h7mvbKvNycFnXUzYwVSLwcFRWS5cfOa5v71RMQZVPz9IEp7cGBn1/0Jj7rEZEK6PzKxleiAFQA9P3cLQ==';

Page({
  data: {
    output: '上方输入框输入数据后点击下方对应按钮转换',
    toEncryptInput: '',
    toDecryptInput: ''
  },
  bindEncryptInput: function (e) {
    this.setData({
      toEncryptInput: e.detail.value
    })
  },
  rsaEncrypt: function () {
    var encStr = RSA.encrypt(this.data.toEncryptInput,publicKey);
    this.setData({
      toDecryptInput: encStr
    })
    wx.setClipboardData({
      data: encStr,
      success: function () {
        wx.showToast({
          title: '复制成功',
          duration: 1000
        })
      }
    })
  },
  rsaDecrypt: function () {
      var decStr =RSA.decrypt(this.data.toDecryptInput,privateKey)
      this.setData({
        toEncryptInput: decStr
      })
      wx.setClipboardData({
        data: decStr,
        success: function () {
          wx.showToast({
            title: '复制成功',
            duration: 1000
          })
        }
      })
  }
})